#include"UnitLM.h"

#include"Field.h"
#include"Map.h"

#include<stdio.h>

UnitLM::UnitLM(Map *map, UnitAge age, Team team):Unit(map, team, _getFullName(age), "LM", age){
	_initStats(age);
	m_hasRetaliated = false;
}

UnitLM::~UnitLM(){
	
}

//TODO: This could probably use some tweaking.
///Regardless, this should suffice for now.
double UnitLM::getAttackPriority(const Unit *unit)const{
	double priority = 0;
	priority += (10 - unit->health());
	if(unit->type() == TYPE_FM)
		priority += 10;
	else if(unit->type() != TYPE_HM)
		priority += 5;
	priority += unit->attack(true)/100.0;
	priority -= unit->defense(true)/100.0;
	return priority;
}

int UnitLM::getFieldPriorityForField(Field *field)const{
	if(field->type() == FIELD_FOREST)
		return 2;
	else if(field->type() == FIELD_BUSH)
		return 1;
	return 0;
}

QString UnitLM::_getFullName(UnitAge age){
	switch(age){
		case AGE_BRZ:
			return "Spearfighter";
		case AGE_IRN:
			return "Soldier";
		case AGE_EMA:
			return "Mercenary";
		case AGE_HMA:
			return "Berserker";
		case AGE_LMA:
			return "Great Sword Warrior";
		case AGE_CA:
			return "Ranger";
		case AGE_IA:
			return "Jaeger Infantry";
		default:
			return "Spearfighter";
	}
}

void UnitLM::_initStats(UnitAge age){
	switch(age){
		case AGE_BRZ:
			m_attack = 7;
			m_defense = 7;
			m_range = 1;
			m_speed = 14;
			m_defenseBonusBush = 2;
			m_defenseBonusForest = 3;
			m_attackBonusFM = 3;
			m_defenseBonusFM = 3;
			break;
		case AGE_IRN:
			m_attack = 9;
			m_defense = 9;
			m_range = 1;
			m_speed = 16;
			m_defenseBonusBush = 3;
			m_defenseBonusForest = 4;
			m_attackBonusFM = 4;
			m_defenseBonusFM = 4;
			break;
		case AGE_EMA:
			m_attack = 13;
			m_defense = 13;
			m_range = 1;
			m_speed = 16;
			m_defenseBonusBush = 3;
			m_defenseBonusForest = 5;
			m_attackBonusFM = 5;
			m_defenseBonusFM = 5;
			break;
		case AGE_HMA:
			m_attack = 20;
			m_defense = 16;
			m_range = 1;
			m_speed = 12;
			m_defenseBonusBush = 4;
			m_defenseBonusForest = 6;
			m_attackBonusFM = 6;
			m_defenseBonusFM = 6;
			break;
		case AGE_LMA:
			m_attack = 25;
			m_defense = 25;
			m_range = 1;
			m_speed = 16;
			m_defenseBonusBush = 4;
			m_defenseBonusForest = 7;
			m_attackBonusFM = 7;
			m_defenseBonusFM = 7;
			break;
		case AGE_CA:
			m_attack = 35;
			m_defense = 35;
			m_range = 1;
			m_speed = 16;
			m_defenseBonusBush = 7;
			m_defenseBonusForest = 10;
			m_attackBonusFM = 10;
			m_defenseBonusFM = 10;
			break;
		case AGE_IA:
			m_attack = 28;
			m_defense = 37;
			m_range = 6;
			m_speed = 16;
			m_defenseBonusBush = 10;
			m_defenseBonusForest = 14;
			m_attackBonusFM = 15;
			m_defenseBonusFM = 15;
			break;
	}
}

int UnitLM::defenseTerrainBonus()const{
	if(field()->type() == FIELD_BUSH)
		return m_defenseBonusBush;
	else if(field()->type() == FIELD_FOREST)
		return m_defenseBonusForest;
	return 0;
}

int UnitLM::defenseBonusAgainst(UnitType type)const{
	int bonus = defenseTerrainBonus();
	if(type == TYPE_FM)
		bonus += m_defenseBonusFM;
	return bonus;
}

int UnitLM::attackBonusAgainst(UnitType type)const{
	if(type == TYPE_FM)
		return m_attackBonusFM;
	return 0;
}

/*	switch(age){
		case AGE_BRZ:
			break;
		case AGE_IRN:
			break;
		case AGE_EMA:
			break;
		case AGE_HMA:
			break;
		case AGE_LMA:
			break;
		case AGE_CA:
			break;
		case AGE_IA:
			break;
		default:
			break;
	}*/